/*    */ package com.zimbra.cs.service.account;
/*    */ 
/*    */ import com.zimbra.common.calendar.TZIDMapper;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AccountConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.HashSet;
/*    */ import java.util.Map;
/*    */ import java.util.Map.Entry;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetPrefs
/*    */   extends AccountDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 40 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 41 */     Account account = getRequestedAccount(zsc);
/*    */     
/* 43 */     if (!canAccessAccount(zsc, account)) {
/* 44 */       throw ServiceException.PERM_DENIED("can not access account");
/*    */     }
/* 46 */     Element response = zsc.createElement(AccountConstants.GET_PREFS_RESPONSE);
/* 47 */     handle(request, response, account);
/* 48 */     return response;
/*    */   }
/*    */   
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   public static void handle(Element request, Element response, Account acct)
/*    */     throws ServiceException
/*    */   {
/* 61 */     HashSet<String> specificPrefs = null;
/* 62 */     for (Element epref : request.listElements("pref")) {
/* 63 */       if (specificPrefs == null)
/* 64 */         specificPrefs = new HashSet();
/* 65 */       specificPrefs.add(epref.getAttribute("name"));
/*    */     }
/*    */     
/* 68 */     Map<String, Object> map = acct.getUnicodeAttrs();
/* 69 */     if (map != null) {
/* 70 */       doPrefs(acct, response, map, specificPrefs);
/*    */     }
/*    */   }
/*    */   
/*    */   public static void doPrefs(Account acct, Element prefs, Map<String, Object> attrsMap, HashSet<String> specificPrefs) {
/* 75 */     for (Map.Entry<String, Object> entry : attrsMap.entrySet()) {
/* 76 */       String key = (String)entry.getKey();
/*    */       
/* 78 */       if (((specificPrefs == null) || (specificPrefs.contains(key))) && 
/*    */       
/* 80 */         (key.startsWith("zimbraPref")))
/*    */       {
/*    */ 
/* 83 */         Object value = entry.getValue();
/* 84 */         if ((value instanceof String[])) {
/* 85 */           String[] sa = (String[])value;
/* 86 */           for (int i = 0; i < sa.length; i++) {
/* 87 */             prefs.addKeyValuePair(key, sa[i], "pref", "name");
/*    */           }
/*    */         } else {
/* 90 */           if (key.equals("zimbraPrefTimeZoneId"))
/* 91 */             value = TZIDMapper.canonicalize((String)value);
/* 92 */           prefs.addKeyValuePair(key, (String)value, "pref", "name");
/*    */         }
/*    */       }
/*    */     }
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/GetPrefs.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */